package com.ax.center.controller;

import com.ax.center.annotation.Logging;
import com.ax.center.dto.ApiResponse;
import com.ax.center.dto.NewUserDTO;
import com.ax.center.entity.Users;
import com.ax.center.service.UsersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zy
 * @date 2023/7/4 14:39
 */

@RestController
@RequestMapping(value = "userController")
@Api(tags = "用户服务")
@CrossOrigin(origins = "http://localhost:5173")
public class UserController {

    @Autowired
    private UsersService usersService;

    @PostMapping("/无效的请求")
    public void test(@RequestBody Users users){
        return;
    }
    @GetMapping(value = "/updatePW/{id}/{password}")
    @ApiOperation(value = "修改密码接口")
    @Logging(description = "修改密码")
    public ApiResponse updatePW(@PathVariable(value = "id")Long id,@PathVariable(value = "password")String newPW){
        System.out.println(1111);
        return usersService.updatePW(id,newPW);
    }

    @GetMapping(value = "queryUserByDeName/{depName}")
    @ApiOperation(value = "查询部门里面所有的人")
    @Logging(description = "查询部门里面所有的人")
    public ApiResponse queryUserByDeName(@PathVariable("depName")String depName){
        return  usersService.queryUserByDeName(depName);
    }

    @GetMapping(value = "queryUserByName/{userName}")
    @ApiOperation(value = "根据名字查询用户信息")
    @Logging(description = "根据名字查询用户信息")
    public  ApiResponse queryUserByName(@PathVariable("userName")String userName){
        return  usersService.queryUserByName(userName);
    }

    @GetMapping(value = "queryAllDeName")
    @ApiOperation(value = "查询所有部门")
    @Logging(description = "查询所有部门")
    public  ApiResponse queryAllDeName(){
        return  usersService.queryAllDeName();
    }

    @GetMapping(value = "queryByStaffId/{id}")
    @ApiOperation(value = "根据工号查询用户")
    @Logging(description = "根据工号查询用户")
    public ApiResponse queryByStaffId(@PathVariable("id")Long id){
        return usersService.queryByStaffId(id);
    }



    @GetMapping(value = "/queryAll")
    @ApiOperation(value = "查询用户信息")
    @Logging(description = "查询用户信息")
    public ApiResponse queryAll(){
        return usersService.queryAll();
    }


    @PostMapping(value = "/insertUser")
    @ApiOperation(value = "新增用户")
    @Logging(description = "新增用户")
    public ApiResponse insertUser(@RequestBody NewUserDTO newUserDTO){
        return usersService.insertUser(newUserDTO);
    }

    @GetMapping(value = "/deleteUser/{staffId}")
    @ApiOperation(value = "删除用户")
    @Logging(description = "删除用户")
    public ApiResponse deleteUser(@PathVariable("staffId")Long staffId){
        return usersService.deleteUser(staffId);
    }

    @GetMapping(value = "/getAllStaffsWithRoleAndAuth")
    @ApiOperation(value = "查询所有员工的工号，姓名，角色，部门，权限")
    @Logging(description = "查询所有员工的工号，姓名，角色，部门，权限")
    public ApiResponse getAllStaffsWithRoleAndAuth(){
        return usersService.getAllStaffsWithRoleAndAuth();
    }


    @GetMapping(value = "/getAllRolesWithStaffInfo")
    @ApiOperation(value = "角色分组查询所有员工的工号，姓名，角色，部门，权限")
    @Logging(description = "角色分组查询所有员工的工号，姓名，角色，部门，权限")
    public ApiResponse getAllRolesWithStaffInfo(){
        return usersService.getAllRolesWithStaffInfo();
    }

    @GetMapping(value = "/getStaffInfoByRoleName/{roleName}")
    @ApiOperation(value = "根据角色名角色查询所有员工的工号，姓名，角色，部门，权限")
    @Logging(description = "根据角色名查询所有员工的工号，姓名，角色，部门，权限")
    public ApiResponse getStaffInfoByRoleName(@PathVariable("roleName")String roleName){
        return usersService.getStaffInfoByRoleName(roleName);
        }


    @GetMapping(value = "/getStaffInfoByDeName/{deName}")
    @ApiOperation(value = "根据部门查询所有员工的工号，姓名，角色，部门，权限")
    @Logging(description = "根据部门查询所有员工的工号，姓名，角色，部门，权限")
    public ApiResponse getStaffInfoByDeName(@PathVariable("deName")String deName){
        return usersService.getStaffInfoByDeName(deName);
    }

    @GetMapping(value = "/getStaffInfoByUserName/{userName}")
    @ApiOperation(value = "根据用户名查询所有员工的工号，姓名，角色，部门，权限")
    @Logging(description = "根据用户名查询所有员工的工号，姓名，角色，部门，权限")
    public ApiResponse getStaffInfoByUserName(@PathVariable("userName")String userName){
        return usersService.getStaffInfoByUserName(userName);
    }

    @GetMapping(value = "/getStaffInfoByStaffId/{staffId}")
    @ApiOperation(value = "登录根据id返回员工的工号，姓名，角色，部门，权限")
    @Logging(description = "登录根据id返回员工的工号，姓名，角色，部门，权限")
    public ApiResponse getStaffInfoByStaffId(@PathVariable("staffId")Long staffId){
        return usersService.getStaffInfoByStaffId(staffId);
    }

    @GetMapping(value = "/updateDeName/{staffId}/{deName}")
    @ApiOperation(value = "修改部门")
    @Logging(description = "修改部门")
    public ApiResponse updateDeName(@PathVariable("staffId")Long staffId,@PathVariable("deName")String deName){
        return usersService.updateDeName(staffId,deName);
    }


    @GetMapping(value = "/getUserDetailsByStaffId/{staffId}")
    @ApiOperation(value = "修改部门")
    @Logging(description = "修改部门")
    public ApiResponse getUserDetailsByStaffId(@PathVariable("staffId")Long staffId){
        return usersService.getUserDetailsByStaffId(staffId);
    }


    @GetMapping(value = "/getMonitorUrl")
    @ApiOperation(value = "查看系统监控")
    @Logging(description = "查看系统监控")
    public ApiResponse getMonitorUrl(){
        return ApiResponse.ok("http://localhost:9111");
    }



}
